package cn.com.lms.business.user.service;

import cn.com.lms.business.user.persistence.entity.SysUserVo;
import cn.com.lms.business.user.persistence.repository.SysUserVoRepository;
import com.bnzj.core.persistence.BaseService;
import com.bnzj.core.persistence.query.QueryHelpBean;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * @Author: 16266
 * @DateTime: 2020/3/27 17:27
 * @Description: 用户业务层
 */
@Service
public class SysUserVoService extends BaseService<SysUserVoRepository, SysUserVo,Long> {


    public SysUserVo findByAccount(String empNo) {
        return repository.findByAccount(empNo);
    }

    public SysUserVo findByPhone(String phoneNo) {
        return repository.findByPhoneNo(phoneNo);
    }

    /**
     * 查询用户表岗位分类
     * @return
     */
    public List<String> findJobTypeName(){
        return  repository.findJobTypeName();
    }

    public static QueryHelpBean getQueryHelpBean(String querySQL) {
        String selectSQL = " select d.full_name v_dept_full_name, u.* ";
        String whereSQL = " FROM " +
                " bnz_sys_user u " +
                " LEFT JOIN bnz_sys_department d ON u.dept_id = d.id  where  u.account!='admin' " + querySQL;
        QueryHelpBean queryBean = new QueryHelpBean(selectSQL + whereSQL, "select count(1)" + whereSQL,
                SysUserVo.class);
        return queryBean;
    }

    /**
     * 查询岗位人员信息
     */
    public List<Map> findSysUserVoByJobTypeNames(List<String> jobTypeNames){
        if(!CollectionUtils.isEmpty(jobTypeNames)) {

            return repository.findSysUserVoByJobTypeNames(jobTypeNames);
        }
        return  null;
    }

    /**
     * 查询部门人员信息
     */
    public List<Map> findSysUserVoByDepartmentIds(List<Long> departmentIds){
        if(!CollectionUtils.isEmpty(departmentIds)) {
            return repository.findSysUserVoByDepartmentIds(departmentIds);
        }
        return  null;
    }
}
